// pages/Order/actOrderDes/index.js
var QRCode = require('../../../utils/weapp-qrcodes.js')
// const QRCode = require('../../../../utils/weapp-qrcodes.js')
// packageA/pages/Goods/goodsOrder/goodsOrderQRCode/index
var common = require("../../../public.js");
var HttpUrl = common.HttpUrl
var qrcode;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        activityId: ''
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        wx.getStorage({
            key: 'user',
            success: function (res) {
                that.setData({
                    userInfo: res.data.user,
                    token: res.data.token,
                    id: options.id,
                    status: options.status
                }, () => {
                    that.getOrderDes();
                    // that.getOrder();
                })
            }
        })
    },
    getOrderDes: function () {
        var that = this;
        wx.request({
            url: HttpUrl + '/storeActivityOrder/getActivityOrderDetails',
            method: 'GET',
            data: {
                userId: that.data.userInfo.id,
                token: that.data.token,
                orderId: that.data.id
            },
            header: {
                'content-type': 'application/json' // 默认值
            },
            success: function (res) {
                console.log(res.data.data)
                var paymentTime = that.time(res.data.data.paymentTime);
                that.setData({
                    orderDes: res.data.data,
                    paymentTime: paymentTime,
                    activityId: res.data.data.activityId
                }, () => {
                    
                    // qrcode = new QRCode('canvas', {
                    //     text: "checkTicket/event=" + that.data.orderDes.orderNo + "=@" + that.data.userInfo.id + "@#" + that.data.activityId + "#",
                   
                    //     width: 150,
                    //     height: 150,
                    // });
                    var qrcode = new QRCode('canvas', {
                           text: "checkTicket/event=" + that.data.orderDes.orderNo + "=@" 
                           + that.data.userInfo.id + "@#" 
                           + that.data.activityId + "#"
                           +that.data.orderDes.storeId 
                           ,
                   
                        // text:'https://api.feiyanghy.com',
                        width: 150,
                        height: 150,
                        callback: (res) => {  
                          console.log(res.path)
                          that.setData({
                            imgs:res.path
                          })
                      }
                      })
                      that.getOrder();

                })
            }
        })
    },
















    contact() {
        const mobile = this.data.order.consultationPhone
        wx.makePhoneCall({
          phoneNumber: mobile
        })
      },


    getOrder: function () {
        var that = this;
        console.log("打印数据id", that.data.activityId)
        wx.request({
            url: HttpUrl + '/activity/selectActivityById',
            method: 'GET',
            data: {
                userId: that.data.userInfo.id,
                token: that.data.token,
                id: that.data.activityId
            },
            header: {
                'content-type': 'application/json' // 默认值
            },
            success: function (res) {
                that.setData({
                    order: res.data.data
                })
              
            }
        })
    },

    time(time) {
        var now = new Date(time);
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var day = now.getDate();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        if (month <= 9) month = '0' + month;
        if (day <= 9) day = '0' + day;
        if (hours <= 9) hours = '0' + hours;
        if (minutes <= 9) minutes = '0' + minutes;
        var shu = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':00';
        return shu;
    },
})